<template>
  <div>
    <el-dialog title="编辑会员" :visible.sync="obj.isTrue" width="40%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="手机号">
          <el-input v-model="form.phone"></el-input>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="form.nickname"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel()">取 消</el-button>
        <el-button type="primary" @click="enterEdit()">确认编辑</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { memberInfo,memberEdit} from "../../../request/api";
import { successAlert, warningAlert } from "../../../utils/alert";
export default {
  props: ["obj"],
  components: {},
  data() {
    return {
      form: {
        uid: 0,
        nickname: "",
        password: "",
        status: 1,
        phone: "",
      },
    };
  },
  computed: {
    ...mapGetters({
        memberList:"member/list",
    }),
  },
  methods: {
    ...mapActions({
        asyncMemberList:"member/asyncList",

    }),
    empty() {
      this.form = {
        uid: 0,
        nickname: "",
        password: "",
        status: 1,
        phone: "",
      };
    },
    cancel() {
      this.empty()
      this.obj.isTrue = false;
    },
    getOne(uid) {
      memberInfo({ uid: uid }).then((res) => {
        // 给form赋值
        this.form = res.data.list;
        // 置空密码框
        this.form.password = ""
      });
    },
   enterEdit(){
     memberEdit(this.form).then((res) => {
        if (res.data.code == 200) {
          // 成功提示窗
          successAlert(res.data.msg);
          // 关闭当前遮罩层并清空数据
          this.cancel();
          // 重新请求列表数据
          this.asyncMemberList();
        } else {
          // 失败提示窗
          warningAlert(res.data.msg);
        }
      });
  }
  },
  mounted() {
  
  },
};
</script>
<style scoped>
</style>
